package com.lry.basic.design_mode.observer.demo2;

import java.util.Objects;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/11/13
 */
public class User implements Observer {
    private String username;
    private String msg;
    public User(){}
    public User(String username) {
        this.username = username;
    }

    @Override
    public void receive(String msg) {
        this.msg = msg;
        System.out.println("notify " + username + ":" + msg);
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getMsg() {
        return msg;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(username, user.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username);
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                '}';
    }
}
